package com.cloudsigns.factorymanager2.engineering.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.activity.EngineeringPublicationOrderHasBeenReceivedActicity;
import com.cloudsigns.factorymanager2.engineering.activity.EngineeringSurveyOrderHasBeenReceivedActicity;
import com.cloudsigns.factorymanager2.engineering.activity.ReceiveEngineeringBatchInstallationOrderAcitivity;
import com.cloudsigns.factorymanager2.engineering.activity.ReceiveEngineeringConstructOrderActivity;
import com.cloudsigns.factorymanager2.engineering.activity.ReceiveMaintenanceOrderActivity;
import com.cloudsigns.factorymanager2.engineering.activity.ViewEngineeringConstructOrderDetailActivity;
import com.cloudsigns.factorymanager2.engineering.activity.ViewEngineeringInstallOrderDetailActivity;
import com.cloudsigns.factorymanager2.engineering.adapter.WattingToReceiveEngineeringOrderAdapter;
import com.cloudsigns.factorymanager2.engineering.bean.OrderParentBean;
import com.cloudsigns.factorymanager2.project.activity.EngineeringInstallationOrderDetailActivity;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 工单 退回
 * Created by tony on 2018/1/25.
 */

public class BackEngineeringOrderFragment extends Fragment {
    private final String TAG = "BackEngineeringOrderFragment";
    private ListView lv;
    private WattingToReceiveEngineeringOrderAdapter adapter;
    private List<OrderParentBean> designTypeBeanList = new ArrayList<>();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_watting_to_receive_engineering_order, null);
        lv = view.findViewById(R.id.lv);


        adapter = new WattingToReceiveEngineeringOrderAdapter(getActivity(), TAG);
        adapter.setData(designTypeBeanList);
        lv.setAdapter(adapter);


        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                Intent mIntent;
                OrderParentBean order = designTypeBeanList.get(position);

                if (null != order.getCategory()) {
                    CommonEnum.EngineeringORderCategory category = order.getCategory();
                    // 工程安装
                    if (category == CommonEnum.EngineeringORderCategory.INSTALL) {
                        mIntent = new Intent(getActivity(), ViewEngineeringInstallOrderDetailActivity.class);
                        mIntent.putExtra(ConstantUtil.KEY_1, TAG);
                        mIntent.putExtra(ConstantUtil.KEY_2, order);
                        mIntent.putExtra("status","BackEngineeringOrderFragment");
                        startActivity(mIntent);
//                        mIntent = new Intent(getActivity(), EngineeringInstallationOrderDetailActivity.class);
//                        startActivity(mIntent);
                    }
                    // 批量安装
                    else if (category == CommonEnum.EngineeringORderCategory.BATCH_INSTALL) {
                        mIntent = new Intent(getActivity(), ReceiveEngineeringBatchInstallationOrderAcitivity.class);
                        mIntent.putExtra("type","BackEngineeringOrderFragment");
                        startActivity(mIntent);
                    }
                    // 工程施工
                    else if (category == CommonEnum.EngineeringORderCategory.CONSTRUCT) {
                        mIntent = new Intent(getActivity(), ViewEngineeringConstructOrderDetailActivity.class);
                        mIntent.putExtra(ConstantUtil.KEY_1, TAG);
                        mIntent.putExtra(ConstantUtil.KEY_2, order);
                        mIntent.putExtra("type","BackEngineeringOrderFragment");
                        startActivity(mIntent);
                    }
                    // 维修单
                    else if (category == CommonEnum.EngineeringORderCategory.MAINTAIN) {
                        mIntent = new Intent(getActivity(), ReceiveMaintenanceOrderActivity.class);
                        mIntent.putExtra("type","BackEngineeringOrderFragment");
                        startActivity(mIntent);
                    }
                    // 现场勘查
                    else if (category == CommonEnum.EngineeringORderCategory.SURVEY) {
                        mIntent = new Intent(getActivity(), EngineeringSurveyOrderHasBeenReceivedActicity.class);
                        mIntent.putExtra("type","BackEngineeringOrderFragment");
                        startActivity(mIntent);
                    }
                    // 广告上刊
                    else if (category == CommonEnum.EngineeringORderCategory.PUBLICATION) {
                        mIntent = new Intent(getActivity(), EngineeringPublicationOrderHasBeenReceivedActicity.class);
                        mIntent.putExtra("type","BackEngineeringOrderFragment");
                        startActivity(mIntent);
                    }
                }
            }
        });
        return view;
    }


    public void initData(List<OrderParentBean> engineeringOrderBeanList) {
        if (engineeringOrderBeanList != null) {
            designTypeBeanList.clear();
            designTypeBeanList.addAll(engineeringOrderBeanList);
            adapter.setData(designTypeBeanList);
            adapter.notifyDataSetChanged();
        }
    }
}
